<!DOCTYPE html>
<html lang="en">

	<head>
		<meta charset="UTF-8">
		<title>Title</title>
		<script src="js/jquery-3.0.0.js"></script>
	</head>

	<body>
		姓名：<input type="text" id="name"/>
		<br />
		班级：<select id="select1">
				<option id="-1">请选择</option>
			</select>
		<button id="query">综合查询</button>
		<table id="table1" border="1px" cellpadding="0" cellspacing="0">
			<tr>
				<td>ID</td>
				<td>姓名</td>
				<td>性别</td>
				<td>年级</td>
				<td>班级</td>
				<td>操作</td>
			</tr>
		</table>
		
		<div>
			<table cellpadding="" cellspacing="">
				<tr>
					<td>ID</td>
					<td>
						<input type="text" readonly="readonly" value="ID已设为自动增长"/>
					</td>
				</tr>
				<tr>
					<td>姓名</td>
					<td>
						<input type="text" id="names"/>
					</td>
				</tr>
				<tr>
					<td>性别</td>
					<td>
						<select id="sexs">
							<option>男</option>
							<option>女</option>
						</select>
					</td>
				</tr>
				<tr>
					<td>年龄</td>
					<td>
						<input type="text" id="age"/>
					</td>
				</tr>
				<tr>
					<td>班级</td>
					<td>
						<select id="select2">
							
						</select>
					</td>
				</tr>
				<tr>
					<td colspan="2">
						<button id="save">添加</button>
					</td>
				</tr>
			</table>
		</div>
	</body>

</html>
<script>
	//网页加载事件 方法
	function query() {
		$("#table1 tr").not(':eq(0)').remove();
		$.ajax({
			type: "POST",
			url: "student/query",
			data: {
				"name":$("#name").val(),
				"cid":$(":selected","#select1").attr("id")
			},
			success: function(msg) {
				$.each(msg.student2, function(index,obj) {
					$("#table1").append(
						"<tr>"+
						"<td>"+obj.stuid+"</td>"
						+"<td>"+obj.name+"</td>"
						+"<td>"+obj.sex+"</td>"
						+"<td>"+obj.age+"</td>"
						+"<td>"+obj.cname+"</td>"
						+"<td> <button id='"+obj.stuid+"' class='delete'>删除</button> <button>修改</button> </td>"
						+"</tr>"
					)
				});
				
				$.each(msg.classes, function(index,obj2) {
					$("#select1").append(
						"<option id='"+obj2.cid+"'>"+obj2.cname+"</option>"
					)
					$("#select2").append(
						"<option id='"+obj2.cid+"'>"+obj2.cname+"</option>"
					)
				});
			}
		});
	}
	
	
	$(function() {
		query();
		
		//综合查询
		$("#query").click(function(){
			  query();
			  $("#select1 option").not(':eq(0)').remove();
		});
		
		//删除
		$(document).on("click",".delete",function(){
			$.ajax({
			type: "POST",
			url: "student/delete",
			data: {
				"stuid":$(this).attr("id")
			},
			success: function(msg) {
				query();
			}
		});
		});
		
		//添加
		$("#save").on("click").Function(){
			$.ajax({
			type: "POST",
			url: "student/save",
			data: {
				"stuid":$("#names").val(),
				"stuid":$(this).attr("id"),
				"stuid":$(this).attr("id"),
				"stuid":$(this).attr("id"),
				"stuid":$(this).attr("id"),
			},
			success: function(msg) {
				query();
			}
		});
		});
		
	});
</script>